package de.jmda.core.util;

import java.io.File;

import javax.tools.JavaFileObject.Kind;

import de.jmda.core.util.fileset.FileSet;
import de.jmda.core.util.fileset.FileSet.RuleSetUpdateMode;

public abstract class FileUtil
{
	public static File toSourceFile(Class<?> clazz)
	{
		return new File(toSourceFilePath(clazz));
	}

	public static String toSourceFilePath(Class<?> clazz)
	{
		return
				toPackagePath(clazz)
				+ File.separatorChar + clazz.getSimpleName() + Kind.SOURCE.extension;
	}

	public static String toPackagePath(Class<?> clazz)
	{
		return toPackagePath(clazz.getPackage().getName());
	}

	public static String toPackagePath(Package package_)
	{
		return toPackagePath(package_.getName());
	}

	public static String toPackagePath(String packagename)
	{
		return packagename.replace('.', File.separatorChar);
	}

	public static FileSet createFileSet(Class<?> clazz, File rootDirectory)
	{
		File file = new File(rootDirectory, toSourceFilePath(clazz));

		FileSet result = new FileSet();
		
		result.includeFile(file, RuleSetUpdateMode.ADD_RULE);
		
		return result;
	}

	public static FileSet createFileSet(Class<?> clazz, String rootDirectory)
	{
		return createFileSet(clazz, new File(rootDirectory));
	}
}